package com.kkb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kkb.entity.User;
import com.kkb.mapper.UserMapper;
import com.kkb.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.function.Consumer;

@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(String username, String password) {
        QueryWrapper<User> emailWrapper = Wrappers.<User>query().eq("email", username).eq("password", password);
        User user = userMapper.selectOne(
                Wrappers.<User>query().
                        eq("username", username).
                        eq("password", password));
        if (user == null) {
            user = userMapper.selectOne(emailWrapper);
        }
        return user;
    }
}
